#include <iostream>
#include <sstream>
#include <string>
#include <chrono>
#include <iomanip>
#include <unistd.h>

std::string GetDateTimeString()
{
    auto now = std::chrono::system_clock::now();
    std::time_t now_c = std::chrono::system_clock::to_time_t(now);
    auto now_ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000;

    std::ostringstream oss;
    oss << std::put_time(std::localtime(&now_c), "%Y-%m-%d %H:%M:%S");
    oss << '.' << std::setfill('0') << std::setw(3) << now_ms.count();

    return oss.str();
}

int main()
{
    std::string result = GetDateTimeString();
    std::cout << result << std::endl;

    while(1)
    {
        sleep(1);
    }

    return 0;
}

/* 
2024-07-08 17:53:56.933

 */